#include "ECS/Component.h"
#include "ECS/Assembly.h"

namespace ECS
{
	mtBEGIN(Component)
		mtCONSTRUCTOR();
		mtMETHOD(destroy);
	mtEND

	Component::Component() : _assembly(nullptr)
	{

	}

	Component::~Component()
	{

	}

	Assembly* Component::getAssembly() const
	{
		return _assembly;
	}

	void Component::destroy()
	{
		enableConnections(false);
		getAssembly()->destroy(this);
	}

	bool Component::isEnabled() const
	{
		return _enabled;
	}

	void Component::setEnabled(bool enabled)
	{
		if (_enabled == enabled)
			return;
		_enabled = enabled;
		enableConnections(_enabled);
		onEnabled(_enabled);
	}

	void Component::addConnection( const Connection& connection )
	{
		_connections.push_back(connection);
	}

	void Component::enableConnections( bool enable )
	{
		for (size_t i = 0; i < _connections.size(); ++i)
		{
			if (enable) _connections[i].connect(); else _connections[i].disconnect();
		};
	}

	void Component::onDestroyed()
	{

	}

	void Component::onEnabled( bool enabled )
	{

	}

}